package com.sc.nft.service.impl;

import com.sc.nft.dao.ActivityAwardDao;
import com.sc.nft.entity.ActivityAward;
import com.sc.nft.entity.dto.ActivityAwardSaveDTO;
import com.sc.nft.entity.dto.ActivityAwardSaveDetailsDTO;
import com.sc.nft.entity.vo.ActivityAwardSaveDetailsVO;
import com.sc.nft.service.ActivityAwardService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * (ActivityAward)表服务实现类
 *
 * @author 王伟成
 * @since 2023-09-13 15:34:01
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class ActivityAwardServiceImpl implements ActivityAwardService {

    private final ActivityAwardDao activityAwardDao;
    @Override
    public void save(List<ActivityAwardSaveDTO> activityAwardSaveDTO,Long activityBasicsId) {
        List<ActivityAward> activityAwards = new ArrayList<>();
        activityAwardSaveDTO.forEach(data -> {
            data.getActivityAwardSaveDetails().forEach(result -> {
                ActivityAward activityAward = new ActivityAward();
                activityAward.setAwardLv(data.getAwardLv());
                activityAward.setAwardLvName(data.getAwardLvName());
                activityAward.setActivityBasicsId(activityBasicsId);
                activityAward.setPropType(result.getPropType());
                activityAward.setPropId(result.getPropId());
                activityAward.setPropName(result.getPropName());
                activityAward.setPropNum(result.getPropNum());
                activityAwards.add(activityAward);
            });
        });
        activityAwardDao.saveBatch(activityAwards);
    }

    @Override
    public List<ActivityAward> getByActivityBasicsId(Long activityBasicsId) {
        return activityAwardDao.getByactivityBasicsId(activityBasicsId);
    }

    @Override
    public void saveActivityAward(Long activityAwardId, List<ActivityAwardSaveDetailsDTO> activityAwardSaveDetailsDTOS,Long activityBasicsId) {
        List<ActivityAward> activityAwards = new ArrayList<>();
        //新增奖励
        activityAwardSaveDetailsDTOS.forEach(activityAwardSaveDetailsDTO -> {
            ActivityAward activityAward = new ActivityAward();
            activityAward.setAwardLv(1);//奖励排名
            activityAward.setAwardLvName("签到奖励");//签到奖励
            activityAward.setActivityAwardId(activityAwardId);
            activityAward.setActivityBasicsId(activityBasicsId);
            activityAward.setPropType(activityAwardSaveDetailsDTO.getPropType());
            activityAward.setPropId(activityAwardSaveDetailsDTO.getPropId());
            activityAward.setPropName(activityAwardSaveDetailsDTO.getPropName());
            activityAward.setPropNum(activityAwardSaveDetailsDTO.getPropNum());
            activityAwards.add(activityAward);
        });
        activityAwardDao.saveBatch(activityAwards);
    }


    @Override
    public List<ActivityAwardSaveDetailsVO> getByRewardAllocationId(Long rewardAllocationId) {
        return activityAwardDao.getByRewardAllocationId(rewardAllocationId);
    }
}
